{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "5cc587f2",
   "metadata": {},
   "source": [
    "* 日期：2022-10-12\\week08（周三）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "200128f4",
   "metadata": {},
   "source": [
    "# 1.字符串的性质和方法\n",
    "> 1. 字符串的有序性\n",
    "> 2. 字符串是有长度的\n",
    ">>1.使用len（）检查字符串长度\n",
    "* 字符串的基础方法（运算法则）\n",
    ">1. 字符串取值：str[index]\n",
    ">2. 字符串的切片：str[start,stop],stop取不到\n",
    ">3. 字符串的拼接：+\n",
    ">4. in 检查成员是否存在\n",
    "* 字符串的一般方法 (function)\n",
    ">1. isdigit()\n",
    ">2. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "a61c352e",
   "metadata": {},
   "outputs": [],
   "source": [
    "text = \"广州南方学院团委\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "1a22eabd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "8707365f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'委'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "973a5840",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "37cfd29c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0]+text[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "c010a931",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院团委'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0:8] # 等价于text[:8]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "93627244",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'院团'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[-3:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "238fe5d6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'团委'"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[-2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "b742fac3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院团委广州南方学院团委'"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2*text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4fecfcc4",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "dc88c99d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"广州\"in text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "ed5f74a5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "3 * text.count(\"广州\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "893a31aa",
   "metadata": {},
   "outputs": [],
   "source": [
    "age_1 = 19\n",
    "age_2 = \"19\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "e0332b88",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "19\n"
     ]
    }
   ],
   "source": [
    "print (age_1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c98b2bad",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "95ebfe78",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "38\n"
     ]
    }
   ],
   "source": [
    "#如果字符串是数值，可以用int转化成真正的数值\n",
    "if age_2.isdigit():\n",
    "    print(age_1 + int(age_2))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "85a1bcac",
   "metadata": {},
   "source": [
    "## 2.有序的数据结构-列表\n",
    "\n",
    "> 1.列表的概念和基本性质"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b231e774",
   "metadata": {},
   "source": [
    "### 2.1 列表的性质\n",
    "\n",
    "* 和字符串的运算法则完全一致\n",
    "* 注意： 字符串是对字符进行操作，列表是对item"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "918bc639",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25]"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 列表的形式\n",
    "squares = [1,4,9,16,25] # 列表里面放数据\n",
    "squares"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "1bfcd86e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'alex', 'Marry', 'Jan']"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name = [\"jack\",\"alex\",\"Marry\",\"Jan\"] # 列表里面放字符串\n",
    "name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "fe4d1f55",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jake', 18, '李华', 20]"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "info = [\"jake\",18,\"李华\",20]\n",
    "info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "ee786bd6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25, 'jack', 'alex', 'Marry', 'Jan']"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares + name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "77a20576",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['alex', 'Marry']"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name[1:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f106def5",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 取出\"j\",\"m\"用切片的方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "9ce622b5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'Marry']"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name[:3:2]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "708b10e7",
   "metadata": {},
   "source": [
    "|sfsdsfs|"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4ce24a65",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
